package com.feihao.zhou.demo01;

import java.sql.*;

/**
 * 查看db3的user表
 */
public class JDBCDemo02 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.注册驱动：
        Class.forName("com.mysql.jdbc.Driver");//5.5把呢不能后可省略

        //2.获取连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.26.1:3306/db3", "root", "root");
        //url:jdbc:mysql://ip地址（域名）:端口号/数据库名称
        //3.获取执行者对象
        //获取普通执行者对象
//        Statement statement = connection.createStatement();
        PreparedStatement preparedStatement = connection.prepareStatement("SELECT * from user where name='张三'");

        //
        //4.执行sql语句
        ResultSet resultSet = preparedStatement.executeQuery();


        while (resultSet.next()) {
            System.out.println(resultSet.getInt("id") + resultSet.getString("name") + resultSet.getString("address"));
        }
        //6.释放资源：
        preparedStatement.close();
        connection.close();
        resultSet.close();

    }
}
